網際內容管理系統在精密機械教學與研究上的應用

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • 主機設定
    • Windows 10
      • Win 網站簽章
      • Win Oauth2
      • Oauth2 原理
      • Nginx
    • Ubuntu設定
      • Ubuntu 簽章
      • 配置 uwsgi
      • xrdp
  • fossiloauth
    • foauth_config
  • fossilapp
  • Fossil
  • 專題報告
  • Reference
    • Flutter
      • Flutter ref
    • discourse
      • 操作管理
    • cd2020pj1
      • Oauth2
    • Network
    • Ref
      • LaTeX
      • Automatic Control
      • 參考步驟
      • ebook1
      • Project
      • Ref2
      • Bond Graphs
      • KMOLBrowser
      • Glowscript
      • Rapydscript
      • Atoms
      • Samples
      • RLearning
      • Ebooks
      • Feedback
      • CMSiMDE
      • Git
      • Windows
      • Ubuntu
      • Heorku
      • Certbot
Win 網站簽章 << Previous Next >> Oauth2 原理

Win Oauth2

這裡將要說明如何在 Windows 10 環境下配置 https://github.com/mdecourse/fossiloauth. 其中將牽涉如何透過 waitress 啟動 Flask, 此設定就如同在 Ubuntu 環境中以 uwsgi 啟動 Flask 網際程式流程, 目的都是希望能以最大效率執行 Flask 網際程式.

首先必須先將 fossiloauth clone 到 c:\pj2022 目錄下.

c:\pj2022>git clone https://github.com/mdecourse/fossiloauth.git

然後在 fossiloauth 目錄中建立一個 waitress_server.py 伺服器啟動程式:

# 執行前, 必須要先利用 pip install waitress 安裝 wairess 模組
# 接著從 waitress 導入 serve
from waitress import serve

# 導入 fossiloauth
import fossiloauth

# run fossiloauth.app with production waitress
serve(fossiloauth.app, host='0.0.0.0', port=5000, url_scheme='https')

接下來的設定必須先登入一個 Gmail 帳號, 然後連結到 https://console.cloud.google.com 中建立 Oauth2 連線時所需的 credential: https://console.cloud.google.com/apis/credentials.

由於目前所需的 Oauth2 認證採用全球資訊網 (Web) 介面, 因此還必須根據網站中的程式架構設定認證用的 uri 連結.

至於 Oauth2 認證希望採 Gmail 帳號, 因此還需至 https://console.cloud.google.com/apis/library 中 enabled Gmail API 的使用權限.

建立 credential 流程如下:

至 https://console.cloud.google.com/apis/credentials 建立一個專案.

在專案項下建立一組 web credential, 其中的 Authorised JavaScript origins 允許連線的 URIs 選擇設為:

https://pj2022.kmol.info:8443, 而 Authorised redirect URIs 則可設為 https://pj2022.kmo.info:8443/login/google/ 表示要使用 port 8443 作為讓使用者登入 Gmail 帳號認證的埠號.

Credential 設定完成後, 可以 downlad 對應的 json 檔案, 以便將此 credential 的 client id 與 client secret 字串檔案, 存在 fossiloauth 目錄之外 (不可以將 credential json 檔案直接放入倉儲, 因為所推送的倉儲都是完全對外公開), 讓採 https://github.com/authomatic/authomatic 的 flaskoauth 能夠正常透過 waitress 啟動執行.

執行 flaskoauth 之前必須透過 pip install authomatic 安裝所需的模組套件.

一旦確認 python waitress_server.py 執行正確後, 就可以再利用 Nssm 以 python.exe 執行參數為 waitress_server.py 的系統服務, 例如:

c:\pj2022\nssm install fossiloauth

由於上述 fossiloauth 是在內部網路以 port 5000 透過 waitress 執行, 因此仍必須利用 Stunnel 將內部 port 5000 的資料轉給外部 8443 的 https 協定連線, 在 config/stunnel.conf 中加入:

[https]
accept = 8443
connect = 5000
cert = fullchain.pem
key = privkey.pem
TIMEOUTclose = 0

意即在加入 flaskoauth 程式執行後的 stunnel.conf 將成為:

; TLS front-end to a web server
[https]
accept  = pj2022.kmol.info:443
connect = 9000
cert = fullchain.pem
key = privkey.pem
TIMEOUTclose = 0

[https]
accept = 8443
connect = 5000
cert = fullchain.pem
key = privkey.pem
TIMEOUTclose = 0

也就是內部的 fossil server 在 port 9000 啟動, 但透過 stunnel 接受外部的 port 443 https 連線, 而 flaskoauth 則在內部的 port 5000 以 waitress 啟動, 也是透過 stunnel 接受外部的 port 8443 https 連線.


Win 網站簽章 << Previous Next >> Oauth2 原理

Copyright © All rights reserved | This template is made with by Colorlib